── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(plotly)
Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
Rows: 1540 Columns: 99
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (21): id, possession_team.name.x, team.name.x, player.name.GK.x, oppone...
dbl (66): match_id.x, index, period, minute, second, possession, duration, ...
lgl (11): under_pressure, off_camera, shot.first_time, shot.aerial_won, sho...
time (1): timestamp
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Logistic regression part 2# shot.type.name probably confounded so drop it from model entirely # indicator variablelibrary(broom)ind.vars2 =c("id", 'goal', 'distance.to.gk', 'DistToGoal', 'angle.to.gk', 'angle.to.goal', 'play_pattern.name', 'shot.technique.name', 'shot.body_part.name')shots.varsdata_log =subset(shots_valid_wwc2023_new, select = ind.vars2) %>%drop_na()#splitting into test and test with 80% splitidx_log =createDataPartition(shots.varsdata_log$goal, p =0.8, list = F)train_log = shots.varsdata_log[idx_log,]test_log = shots.varsdata_log[-idx_log,]goal_glm <-glm(goal ~ DistToGoal + angle.to.goal + distance.to.gk + angle.to.gk + play_pattern.name + shot.technique.name + shot.body_part.name, data = train_log, family ="binomial")goal_glm |>tidy() |>print(n=Inf)
plotly_shot_map <-ggplot(data = alex_morgan, aes(x = location.x, y = location.y, color = Predicted_xG, stroke = is.goal_numeric, label = Play_Type, secondlabel = Opponent)) +annotate_pitch(dimensions = pitch_statsbomb) +theme_pitch() +coord_flip(xlim =c(55, 120), ylim =c(-12, 105)) +geom_point(shape =1, size =1.5) +labs(title = glue::glue(" xG Shot Map for Alex Morgan"), color ="xG") +scale_colour_gradientn(colors =c(low ="blue", high ="red"), limits=c(0, 1))ggplotly(plotly_shot_map, tooltip =c("color", "label", "secondlabel"))
Warning in geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomCurve() has yet to be implemented in plotly.
If you'd like to see this geom implemented,
Please open an issue with your example code at
https://github.com/ropensci/plotly/issues
Warning in geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomCurve() has yet to be implemented in plotly.
If you'd like to see this geom implemented,
Please open an issue with your example code at
https://github.com/ropensci/plotly/issues
Warning in geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomCurve() has yet to be implemented in plotly.
If you'd like to see this geom implemented,
Please open an issue with your example code at
https://github.com/ropensci/plotly/issues
Warning in geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomCurve() has yet to be implemented in plotly.
If you'd like to see this geom implemented,
Please open an issue with your example code at
https://github.com/ropensci/plotly/issues
Warning: Aspect ratios aren't yet implemented, but you can manually set a
suitable height/width
Warning: Aspect ratios aren't yet implemented, but you can manually set a
suitable height/width
Warning in geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomCurve() has yet to be implemented in plotly.
If you'd like to see this geom implemented,
Please open an issue with your example code at
https://github.com/ropensci/plotly/issues
Warning in geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomCurve() has yet to be implemented in plotly.
If you'd like to see this geom implemented,
Please open an issue with your example code at
https://github.com/ropensci/plotly/issues
Warning in geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomCurve() has yet to be implemented in plotly.
If you'd like to see this geom implemented,
Please open an issue with your example code at
https://github.com/ropensci/plotly/issues
Warning in geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomCurve() has yet to be implemented in plotly.
If you'd like to see this geom implemented,
Please open an issue with your example code at
https://github.com/ropensci/plotly/issues
Warning: Aspect ratios aren't yet implemented, but you can manually set a
suitable height/width
Warning: Aspect ratios aren't yet implemented, but you can manually set a
suitable height/width
Warning in geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomCurve() has yet to be implemented in plotly.
If you'd like to see this geom implemented,
Please open an issue with your example code at
https://github.com/ropensci/plotly/issues
Warning in geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomCurve() has yet to be implemented in plotly.
If you'd like to see this geom implemented,
Please open an issue with your example code at
https://github.com/ropensci/plotly/issues
Warning in geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomCurve() has yet to be implemented in plotly.
If you'd like to see this geom implemented,
Please open an issue with your example code at
https://github.com/ropensci/plotly/issues
Warning in geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomCurve() has yet to be implemented in plotly.
If you'd like to see this geom implemented,
Please open an issue with your example code at
https://github.com/ropensci/plotly/issues
Warning: Aspect ratios aren't yet implemented, but you can manually set a
suitable height/width
Warning: Aspect ratios aren't yet implemented, but you can manually set a
suitable height/width
# using open point shape to include stroke and color to the shot map# stroke argument needs numeric variables# Expected goals model overall for WWC 2023shots_valid_wwc_log <- shots_valid_wwc_log %>%mutate(is.goal_numeric =if_else(is.goal =="Goal", 1.5, 0.5))a8 = pitch +geom_point(data = shots_valid_wwc_log, aes(x = location.x, y = location.y, color = .fitted, stroke = is.goal_numeric), shape =1, size =2) +labs(color ="Probability of Goal \n (xG)", caption ="Removed Republic of Ireland's goal directly from corner; Darker filled in circles mean goal was scored", title ="Expected Goals Model WWC 2023") +scale_colour_gradientn(colors =c(low ="blue", high ="red"), limits=c(0, 1))a8
Investigating higher probability shots
# higher probability for lob shots why 83% in model only 4 lobs in all of dataset and this went in# https://www.foxsports.com/watch/play-68cf11a10000102shots.varsdata_log %>%group_by(shot.technique.name, goal) %>%summarise(n())
`summarise()` has grouped output by 'shot.technique.name'. You can override
using the `.groups` argument.
# south africa goal vs sweden - tap in with chest - high probability # https://www.foxsports.com/watch/play-688491e38000102goal_of_interest <- shots_valid_wwc_log %>%filter(id =="3930cdb9-7755-4f95-b1b1-1babbedb9238")
# Costa Rica vs Zambia# From corner second_goal_interest <- shots_valid_wwc_log %>%filter(id =="db185c6e-74b6-436d-9720-9c4da1517f3e")